extends Node

var utils = null
var ctrl = null
var diff
var base = null
var path = null
var window
var recordWindow
var shop
var research
var charaBuildBonus = 0
var shieldBonus = 1
var endlessopt:bool = false
var rndmode
var keywords
var lists = [[],[],[],[],[]]
var dit = {
	"火系":"AneHekH",
	"水系":"AneHekS",
	"风系":"AneHekF",
	"暗系":"AneHekA",
	"光系":"AneHekG",
}
var dit2 = {
	"AneHekH":0,
	"AneHekS":1,
	"AneHekF":2,
	"AneHekA":3,
	"AneHekG":4,
}
func _ready():
	pass
func _init():
	call_deferred("init")
func _connect():
    pass
    
func init():
	if globalData.infoDs.has("g_AneHekBase"):
		base = globalData.infoDs["g_AneHekBase"]
		path = chaData.infoDs["cTDW"].dir
	if base != null:
		#初始化
		utils = globalData.infoDs["g_AneHekUtils"]
		ctrl = globalData.infoDs["g_AneHek"]
		#base.connect("onStartGame",self,"links")
					
#开始游戏，接收增加角色信号
func links():
	yield(sys.get_tree().create_timer(0.2), "timeout")
	rndmode = base.getSetting("rndMode",false)
	if rndmode:
		keywords = dit[base.getSetting("rndChoose","火系")]
	else:return
	if !ctrl.allflag:return
	sys.main.player.connect("onAddCha",self,"change")
	for i in chaData.rndPool.items:
		var id = i[0].id
		if id.find("cex___AneHek") != -1 && id.find("1") != -1:continue
		if id.find("AneHekGA") != -1 || id.find("AneHekWX") != -1:continue
		if id.find("AneHekH") != -1:
			lists[0].append(id)
		if id.find("AneHekS") != -1:
			lists[1].append(id)
		if id.find("AneHekF") != -1:
			lists[2].append(id)
		if id.find("AneHekA") != -1:
			lists[3].append(id)
		if id.find("AneHekG") != -1:
			lists[4].append(id)
#更改角色系列
func change(cha):
	if cha.id.find(keywords) != -1:return
	var nchaid = sys.rndListItem(lists[dit2[keywords]])
	var ncha = sys.main.newChara(nchaid)
	if cha.lv != 2:
		while(cha.lv != ncha.lv):
			nchaid = sys.rndListItem(lists[dit2[keywords]])
			ncha = sys.main.newChara(nchaid)
	else:
		nchaid = "c" + keywords + "_1"
		ncha = sys.main.newChara(nchaid)
	yield(sys.get_tree().create_timer(0.2), "timeout")
	var flag = 0
	for i in sys.main.btGrid.get_children():
		if is_instance_valid(i) and i.get_children().size() != 0:
			var tcha:Chara = i.get_child(0)
			if tcha.id == cha.id:
				sys.main.btGrid.remove_child(i)
				flag = 1
				break
	if !flag:cha.delself()
	#sys.main.player.delCha(cha)
	sys.main.player.addCha(ncha)